package cn.bkrc.product.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Destination;
import javax.jms.Queue;
import javax.jms.Topic;

@RestController
public class qat_ProductController {

    //注入Queue
    @Autowired
    private Queue queue;
    //注入Topic
    @Autowired
    private Topic topic;
    //注入工具类
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;
    //接收前端的请求，把数据发送到Queue
    @RequestMapping("/queue")
    public String sendQueue(String name){
        //
        //把消息发送到指定队列
        this.sendMessage(queue,name);
        return "success";
    }
    //接收前端的请求，把数据发送到Topic
    @RequestMapping("/topic")
    public String sendTopic(String name){
        //把消息发送到指定队列
        this.sendMessage(topic,name);
        return "success";
    }
    //把消息发送到指定队列的方法
    public void sendMessage(Destination destination, String message){
        jmsMessagingTemplate.convertAndSend(destination,message);
    }
}
